﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Product.Domain.Entity;
using Product.EntityFrameworkCore.PO;

namespace Product.EntityFrameworkCore.MapConfiguration
{
    public class SkuMapConfiguration : IEntityTypeConfiguration<SkuPo>
    {
        public void Configure(EntityTypeBuilder<SkuPo> builder)
        {
            builder.ToTable("t_sku");
            builder.HasKey("Id");
            builder.Property(e => e.Id).HasMaxLength(64).IsRequired();
            builder.Property(e => e.PicUrl).HasMaxLength(64).IsRequired();
            builder.Property(e => e.Price).HasColumnType("decimal(8,2)").IsRequired();
            builder.Property(e => e.Specification).HasMaxLength(200).IsRequired();
            builder.Property(e => e.SalesStatus).HasColumnType("int").IsRequired();
            builder.Property(e => e.SpuId).HasMaxLength(200).IsRequired();
            builder.Property(e => e.UnitId).HasMaxLength(64).IsRequired();
            builder.Property(e => e.Stock).IsRequired();
            builder.HasOne(e => e.Unit).WithOne().HasForeignKey<SkuPo>(e => e.UnitId);
            //builder.HasQueryFilter(e => e.SalesStatus == SalesStatus.OnShelf);
        }
    }
}
